'use strict';

const Controller = require('egg').Controller;
const { uuid } = require('../../utils/index')
class AdminController extends Controller {

    /**
     * //添加项目
     * 
     * @memberof AdminController
     */
    async addProject() {
        let { ctx, service } = this;
        let params = ctx.request.body;
        let param = { ...params,
            user_id: ctx.session.user.user_id,
            system_id: uuid(32),
            system_time: `${(new Date().toLocaleDateString())} ${(new Date().toLocaleTimeString())}`
        };
        let res = await service.admin.admin.addProjectModel(param);
        if (res.rows > 0) {
            ctx.body = {
                success: true,
                msg: '添加成功'
            }
        } else {
            ctx.body = {
                success: false,
                msg: '添加失败'
            }
        }
    }
    /**
     *  删除接口
     * 
     * @memberof AdminController
     */
    async delProject() {
        let { ctx, service } = this;
        let parmas = ctx.query;
        let res = await service.admin.admin.deleteProjectModel(parmas.system_id);
        if (res.rows > 0) {
            ctx.body = {
                success: true,
                msg: '删除成功'
            }
        } else {
            ctx.body = {
                success: false,
                msg: '删除失败'
            }
        }
    }
    /**
     * 修改接口
     * 
     * @memberof AdminController
     */
    async editProject() {
        let { ctx, service } = this;
        let params = ctx.request.body;
        let userId = ctx.session.user.user_id;
        let system_time = `${(new Date().toLocaleDateString())} ${(new Date().toLocaleTimeString())}`
        let res = await service.admin.admin.editProjectModel({ ...params, system_time, user_id: userId });
        if (res.rows > 0) {
            ctx.body = {
                success: true,
                msg: '修改成功'
            }
        } else {
            ctx.body = {
                success: false,
                msg: '修改失败'
            }
        }
    }



}

module.exports = AdminController;